package edu.pku.sei.modeler.editpolicies;

import org.eclipse.gef.EditPart;
import org.eclipse.gef.Request;
import org.eclipse.gef.commands.Command;
import org.eclipse.gef.editpolicies.XYLayoutEditPolicy;
import org.eclipse.gef.requests.CreateRequest;

import edu.pku.sei.modeler.model.structure.MetaNode;

/**
 * @deprecated
 * @author zl
 *
 */
public class TemplateNodePolicy extends XYLayoutEditPolicy {

	protected Command createAddCommand(EditPart childEditPart, Object constraint) {
		/*
		 * if (childEditPart.getModel() instanceof Role) { Role part = (Role)
		 * childEditPart.getModel(); Rectangle rect = (Rectangle) constraint;
		 * CreateRoleCommand create = new CreateRoleCommand();
		 * create.setParent((Task) (getHost().getModel()));
		 * create.setRole(part);
		 * 
		 * return create; }
		 */
		return null;
	}

	protected Command getCreateCommand(CreateRequest request) {
		if (request.getNewObject() instanceof MetaNode) {
			MetaNode node = (MetaNode) request.getNewObject();
//			Object model = node.getElement();
//			if (model instanceof TemplatePort) {
//				MetaNode parent = (MetaNode) (getHost().getModel());
//				Rectangle rect = new Rectangle(parent.getLocationX(), parent.getLocationY(),
//						parent.getWidth(), parent.getHeight());
//				CreateNodeCommand cmd = new CreateNodeCommand(node, parent.getDiagram(), rect);
//				cmd.setParent(parent);
//				return cmd;
//			}
//			else if(model instanceof TemplateSubNode) {
//				CreateSubNodeCommand cmd = new CreateSubNodeCommand();
//				cmd.setSubNode((MetaNode)request.getNewObject());
//				MetaNode parent = (MetaNode) (getHost().getModel());
//				Rectangle rect = (Rectangle) getConstraintFor(request);
//				cmd.setRect(rect);
//				cmd.setOwner(parent);
//				return cmd;
//			}
//			else if(model instanceof MetaClass) {
//				boolean inter = ((MetaClass)model).isInterface();
//				if(inter) {
//					MetaNode parent = (MetaNode) (getHost().getModel());
//					Rectangle rect = new Rectangle(parent.getLocationX(), parent.getLocationY(),
//							parent.getWidth(), parent.getHeight());
//					CreateInterfaceCommand cmd = new CreateInterfaceCommand(node, parent.getDiagram(), rect);
//					cmd.setParent(parent);
//					return cmd;
//				}
//			}
		}
		return null;
	}

	protected Command getDeleteDependantCommand(Request request) {
		return null;
	}

	protected Command createChangeConstraintCommand(EditPart child, Object constraint) {
//		if(child.getModel() instanceof MetaNode) {
//			Object model = ((MetaNode)child.getModel()).getElement();
//			if(model instanceof TemplateSubNode) {
//				Rectangle bounds = (Rectangle)constraint;
//				return new ChangeConstraintCommand(
//						(MetaNode)child.getModel(), bounds.getLocation(), bounds.width, bounds.height);
//			}
//		}
		return null;
	}
}
